<template>
  <div class="dispatch-froms-page">
    <div class="breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>生产派工管理</el-breadcrumb-item>
        <el-breadcrumb-item>派工单列表</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <el-form inline :model="queryProductionFilters">
      <el-form-item>
        <el-input v-model="queryProductionFilters.drawingNumber" class="w150" placeholder="产品图号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="queryProductionFilters.productName" class="w150" placeholder="产品名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-select v-model="queryProductionFilters.state" class="w150" placeholder="状态" filterable clearable>
          <template v-for="item in stateList">
            <el-option :label="item" :value="item" :key="item"></el-option>
          </template>
        </el-select>
      </el-form-item>
      <!-- <el-form-item>
        <el-select v-model="queryProductionFilters.type" class="w150" placeholder="类型" clearable filterable>
          <el-option label="返修" value="返修"></el-option>
          <el-option label="生产" value="生产"></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-input v-model="queryProductionFilters.noticeNumber" class="w150" placeholder="通知单号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="queryProductionFilters.dispatchFormNumber" class="w150" placeholder="路线单号" clearable></el-input>
      </el-form-item>
      <br />
      <el-form-item label="下单日期：" label-width="150">
        <el-date-picker v-model="queryProductionFilters.beginTime" type="date" placeholder="开始日期"></el-date-picker>
      </el-form-item>
      至&nbsp;&nbsp;&nbsp;
      <el-form-item>
        <el-date-picker v-model="queryProductionFilters.endTime" type="date" placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-button @click="clear()">重置</el-button>
      <el-button type="primary" @click="queryForm()">查询</el-button>
      <el-button type="primary" @click="routerBack()">返回</el-button>
    </el-form>

    <el-table border stripe :data="dispatchForms" row-key="id" @row-dblclick="showDetail" :height="tableHeight">
      <el-table-column type="index" label="序号" align="center" width="50"></el-table-column>
      <el-table-column prop="workingNumber" label="产品工号" align="center" width="95"></el-table-column>
      <el-table-column prop="noticeNumber" label="通知单号" align="center" width="95"></el-table-column>
      <el-table-column prop="sequenceId" label="序列号" align="center" width="70"></el-table-column>
      <el-table-column prop="drawingNumber" label="图号" align="center" width="125"></el-table-column>
      <el-table-column prop="productName" label="品名" align="center" width="150"></el-table-column>
      <el-table-column prop="materialQuality" label="材质" align="center" width="125"></el-table-column>
      <el-table-column prop="dispatchFormNumber" label="路线单号" sortable align="center" width="120"></el-table-column>
      <el-table-column prop="dispatchNumber" label="派工数量" align="center" width="120"></el-table-column>
      <el-table-column prop="createTime" label="派工时间" sortable align="center" width="180"></el-table-column>
      <!-- <el-table-column prop="dispatchFormType" label="类型" align="center" width="75"></el-table-column> -->
      <el-table-column :formatter="cleanType" label="清整方式" align="center" width="120"></el-table-column>
      <el-table-column prop="formState" label="状态" align="center" width="120"></el-table-column>
      <el-table-column prop="finishedNumber" label="完工数量" align="center" width="120"></el-table-column>
      <el-table-column prop="finishTime" label="完工时间" align="center" width="180"></el-table-column>
      <el-table-column prop="remark" label="备注" align="center" min-width="120"></el-table-column>
      <el-table-column label="操作" width="90" fixed="right" align="center">
        <template slot-scope="scope">
          <el-button :id="'btnC1Approve' + scope.row.noticeNumber + scope.row.drawingNumber" size="mini" type="primary" @click="showDetail(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleNoticeSizeChange"
      @current-change="handleNoticeCurrentChange"
      :current-page="queryProductionFilters.page"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="queryProductionFilters.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalForms"
      background
      class="mt10"
    >
    </el-pagination>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { namespace } from 'vuex-class'
import Layout from '@/views/_common/Layout.vue'
import _ from 'lodash'

const vuexLogin = namespace('Login')
const vuexDispatch = namespace('ThreeDispatch')
const vuexDispatchDetail = namespace('DispatchDetail')
@Component({
  components: {
    Layout
  },
  beforeRouteEnter(to, from, next) {
    console.log('路由守卫')
    console.log('from')
    console.log(from.name)
    if (from.name != 'dispatch-details') {
      sessionStorage.setItem('queryParam', '')
    }
    next()
  }
})
export default class Index extends Vue {
  @vuexLogin.State DesignReviewShow: any

  // 派工单列表数据
  @vuexDispatch.State dispatchForms
  @vuexDispatch.State totalForms
  // 派工单列表查询接口
  @vuexDispatch.Action QUERY_DISPATCH
  // 派工单详情查询接口
  @vuexDispatch.Action DETAIL_DISPATCH

  // 进入派工单详情页面的产品ID
  @vuexDispatchDetail.Mutation setProducingId

  stateList: String[] = ['进行中', '待质检确认', '清整中', '整备中', '外协中', '待完工确认', '已完工', '已终止']

  // 查询条件
  queryProductionFilters: any = {
    drawingNumber: '',
    productName: '',
    noticeNumber: '',
    dispatchFormNumber: '',
    state: '',
    type: '',
    page: 1,
    pageSize: 20
  }
  tableHeight: any = '800px'
  /**
   * 页面初始化查询
   */

  created() {
    let params = sessionStorage.getItem('queryParam')
    if (params) {
      this.queryProductionFilters = JSON.parse(params)
    }
    let from = this.$route.params.from
    if (from && from == 'notice') {
      this.queryProductionFilters.drawingNumber = this.$route.params.drawingNumber
    }
    this.QUERY_DISPATCH({ ...this.queryProductionFilters })
    // 获取屏幕高度 设置表格高度
    let screenHeight = document.documentElement.clientHeight
    console.log('获取到的屏幕高度：' + screenHeight)
    this.tableHeight = screenHeight - 325 + 'px'
  }

  /**
   * 查询产品记录
   */
  queryForm() {
    this.QUERY_DISPATCH({ ...this.queryProductionFilters })
  }

  /**
   * 清空重置查询条件
   */
  clear() {
    this.queryProductionFilters = {
      drawingNumber: '',
      productName: '',
      noticeNumber: '',
      dispatchFormNumber: '',
      state: '',
      type: '',
      page: 1,
      pageSize: 20
    }
    this.queryForm()
  }

  /**
   * 页面路由返回
   */
  routerBack() {
    this.$router.back()
  }

  /**
   * 点击按钮查看详情
   */
  async showDetail(form) {
    this.setProducingId(form.producingId)
    sessionStorage.setItem('queryParam', JSON.stringify(this.queryProductionFilters))
    this.$router.push({
      name: 'dispatch-details',
      params: {
        from: 'list',
        formId: form.dispatchFormId,
        noticeNumber: form.noticeNumber,
        workingNumber: form.workingNumber
      }
    })
  }

  cleanType(row) {
    return row.cleanBySelf ? '自清整' : '专人清整'
  }

  handleNoticeSizeChange(newSize) {
    // 分页功能
    this.queryProductionFilters.pageSize = newSize
    this.queryForm()
  }
  handleNoticeCurrentChange(newPage) {
    this.queryProductionFilters.page = newPage
    this.queryForm()
  }
}
</script>

<style lang="scss" scoped>
.dispatch-froms-page {
  padding: 10px 20px 0 20px;
}
.total {
  float: left;
  // display: inline;
  border: 1px solid #ccc;
  margin-right: 30px;
  .total_title {
    width: 200px;
    color: #000;
    height: 260px;
    line-height: 30px;
    text-align: center;
    .text {
      font-size: 18px;
      font-weight: bold;
      margin: 0 5px;
    }
  }

  &:hover {
    color: #000;
    background: #fff;
  }
}
.s1 {
  display: none;
}
.s2 {
  height: 100px;
  display: none;
}
.breadcrumb {
  height: 25px;
  width: 100%;
  border: none;
}
//通知单滚动
.notice-box {
  display: -webkit-box;
  overflow-x: auto;
  /*适应苹果*/
  -webkit-overflow-scrolling: touch;
}

.notice-item {
  height: 270px;
}

/*隐藏掉滚动条*/
.notice-box::-webkit-scrollbar {
  display: none;
}

.layout .operation {
  overflow-x: auto;
}
.el-tabs {
  padding: 0 20px;
  margin: 0px 10px 0;
  border: 1px solid #e4e7ed;
  background-color: #fff;
  .el-tabs__content {
    min-width: 1200px;
  }
}
</style>
